//
//  VOH_S_ViewController.m
//  VoiceOfHeart
//
//  Created by lanou3g on 16/8/15.
//  Copyright © 2016年 吉龙. All rights reserved.
//

#import "VOH_S_ViewController.h"
#import "VOH_SD_RotateButtonOverlayView.h"
#import "VOH_SD_RecommendVC.h"
#import "VOH_SD_RegionalradioVC.h"
#import "VOH_SD_rankinglistVC.h"
#import "VOHFirstViewController.h"
#import "RCAnimatedImagesView.h"
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

@interface VOH_S_ViewController ()<VOH_SD_RotateButtonOverlayViewDelegate,RCAnimatedImagesViewDelegate>

@property(nonatomic,strong) VOH_SD_RotateButtonOverlayView *overView;

@property(nonatomic,strong) UIButton *btn;
@property(nonatomic,strong) UIButton *returnBtn;
@property(nonatomic,strong) RCAnimatedImagesView *animatedImagesView;

@end

@implementation VOH_S_ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"电台首页";
   
    
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"radio_background.jpg"]];
    [self.view addSubview:self.btn];
    
    //添加动态图
    self.animatedImagesView = [[RCAnimatedImagesView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    self.animatedImagesView.delegate = self;
    [self.view insertSubview:self.animatedImagesView belowSubview:self.btn];
    


}

- (NSUInteger)animatedImagesNumberOfImages:(RCAnimatedImagesView*)animatedImagesView
{
    return 2;
}

- (UIImage*)animatedImagesView:(RCAnimatedImagesView*)animatedImagesView imageAtIndex:(NSUInteger)index
{
    return [UIImage imageNamed:@"login_background.png"];
}


#pragma mark - action
- (void)btnClicked:(UIButton*)btn
{
    [self.view addSubview:self.overlayView];
    [self.overlayView show];
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    /*************************  返回按钮  ************************/
    UIButton *returnButton = [UIButton buttonWithType:UIButtonTypeCustom];
    returnButton.frame = CGRectMake(10, 10, 40, 40);
    [returnButton setBackgroundImage:[UIImage imageNamed:@"02"] forState:UIControlStateNormal];
    [self.navigationController.navigationBar addSubview:returnButton];
    [returnButton addTarget:self action:@selector(returnButton:) forControlEvents:UIControlEventTouchUpInside];
    self.returnBtn = returnButton;
    
    [super viewWillAppear:animated];
    [self.animatedImagesView startAnimating];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.returnBtn removeFromSuperview];
    
}


//点击按钮触发返回
-(void)returnButton:(UIButton *)sender{
    VOHFirstViewController * firstVC=[[VOHFirstViewController alloc]init];
    
       firstVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
          [self presentViewController:firstVC animated:YES completion:^{
            
        }];
}





#pragma mark - VOH_SD_RotateButtonOverlayViewDelegate
- (void)didSelected:(NSUInteger)index
{
    
    switch (index) {
        case  0:
        {
            VOH_SD_RegionalradioVC *regional = [[VOH_SD_RegionalradioVC alloc]init];
            [self.navigationController pushViewController:regional animated:YES];
        }
            break;
            
            case  1:
        {
            VOH_SD_RecommendVC *recommend = [[VOH_SD_RecommendVC alloc]init];
            [self.navigationController pushViewController:recommend animated:YES];
        }
            break;
        case  2:
        {
            VOH_SD_rankinglistVC *rankinglist = [[VOH_SD_rankinglistVC alloc]init];
            [self.navigationController pushViewController:rankinglist animated:YES];
        }
       
            break;

            
        default:
            break;
    }
    
    NSLog(@"clicked %zd btn",index);
}



#pragma mark - getter
- (UIButton *)btn
{
    if (_btn == nil) {
        _btn = [[UIButton alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 100) / 2.0,SCREEN_HEIGHT-100, 100, 44)];
        [_btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
//        [_btn setBackgroundColor:[UIColor grayColor]];
        [_btn setTitle:@" 戳这里" forState:UIControlStateNormal];
        
        [_btn.layer setCornerRadius:5];
    }
    return _btn;
}
- (VOH_SD_RotateButtonOverlayView *)overlayView
{
    
    if (_overView == nil) {
        _overView = [[VOH_SD_RotateButtonOverlayView alloc] init];
        [_overView setTitlesArray:@[@"您想要的",@"推荐电台",@"排行榜"]];
        [_overView setTitleImage:@[@"first",@"second",@"third"] ];
        
        [_overView setDelegate:self];
        [_overView setFrame:self.view.bounds];
    }
    return _overView;
}



@end
